package com.qingpeng.pay.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.qingpeng.pay.R;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseActivity;
import com.qingpeng.pay.beans.KefuBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.StringUtils;
import com.qingpeng.pay.utils.ToastUtils;
import com.qingpeng.pay.views.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class KefuActivity extends BaseActivity {

    @BindView(R.id.title)
    TitleBar title;
    @BindView(R.id.ll_invite)
    ImageView llInvite;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_kefu;
    }

    @Override
    protected int getRootViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return 0;
    }

    @Override
    protected void onResume() {
        super.onResume();
        title.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Call<KefuBean> kefu = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).kefu();
        kefu.enqueue(new Callback<KefuBean>() {
            @Override
            public void onResponse(Call<KefuBean> call, Response<KefuBean> response) {
                KefuBean body = response.body();
                if (body.getStatus() != 1) {
                    ToastUtils.showToast(KefuActivity.this, body.getInfo());
                    return;
                }
                if (!StringUtils.isEmpty(body.getData().get(0).getContent())){
                    Glide.with(KefuActivity.this).load(Host.HOST+body.getData().get(0).getContent()).into(llInvite);
                }else{
                    ToastUtils.showToast(KefuActivity.this, "客服功能即将上线");
                }
            }

            @Override
            public void onFailure(Call<KefuBean> call, Throwable t) {
                ToastUtils.showToast(KefuActivity.this, "网络请求错误,请稍后重试");
            }
        });
    }
}
